package com.yanmushi.ms.service.controller;

import com.yanmushi.ms.service.model.TestProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author yinlei
 * @Date 2018/3/27
 * @Desc todo
 */
@RestController
public class HelloController {

    private static final Logger log = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    TestProperties testProperties;
    @Autowired
    Environment environment;
//    @Value("${yms.service.name}")
//    String name;

    @GetMapping("/")
    public String index() {
        return "hello!";
    }

    @GetMapping("/hello")
    public String hello() {
        try {
            Thread.sleep((long) (Math.random() * 2000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "hello feign!";
    }

    @GetMapping("/query")
    public String query(Integer id) {
        log.info("accept request, id: {}", id);
        return "data:" + id;
    }

    @GetMapping("/ms-config")
    public String config() {
        return testProperties.getName() + "  :  ";
    }

    @GetMapping("/menv")
    public Environment getEnvironment() {
        return environment;
    }
}
